@extends('layout.app')
@section('title','Редактирование участника')
@section('content')
    <div class="mt-10">
        <form action="{{ route('members.update', $member->id) }}" method="POST"
              class="grid grid-cols-1 gap-[30px] max-w-[600px]">
            @csrf
            @method('PATCH')


            <div>
                <label for="fullname">ФИО</label>
                <input id="fullname" name="fullname" type="text"
                       class="w-full shadow-sky-200 shadow p-[20px] rounded-[10px]" placeholder="ФИО"
                       value="{{ $member->fullname  }}">
                @error('fullname')
                <div>
                    {{ $message }}
                </div>
                @enderror
            </div>
            <div>
                <label for="birthday">Дата рождения</label>
                <input id="birthday" name="birthday" type="date"
                       class="w-full shadow-sky-200 shadow p-[20px] rounded-[10px]" placeholder="Дата рождения"
                       value="{{ $member->birthday  }}">
                @error('birthday')
                <div>
                    {{ $message }}
                </div>
                @enderror
            </div>
            <div>

                <label for="diagnosis">Диагноз</label>
                <select id="diagnosis" name="diagnosis">

                    @foreach($sickness as $sicknes)

                        <option @selected($sicknes->name === $member->diagnosis) value="{{ $sicknes->name }}">
                            {{ $sicknes->name }}
                        </option>
                    @endforeach


                </select>


                @error('diagnosis')
                <div>
                    {{ $message }}
                </div>
                @enderror
            </div>

            <div>
                <label for="fullname_agent">ФИО представителя</label>
                <input id="fullname_agent" name="fullname_agent" type="text"
                       class="w-full shadow-sky-200 shadow p-[20px] rounded-[10px]" placeholder="ФИО представителя"
                       value="{{ $member->fullname_agent  }}">
                @error('fullname_agent')
                <div>
                    {{ $message }}
                </div>
                @enderror
            </div>
            <div>
                <label for="agent_phone">Телефон представителя</label>
                <input id="agent_phone" name="agent_phone" type="text"
                       class="w-full shadow-sky-200 shadow p-[20px] rounded-[10px]" placeholder="Телефон представителя"
                       value="{{ $member->agent_phone  }}">
                @error('agent_phone')
                <div>
                    {{ $message }}
                </div>
                @enderror
            </div>
            <div>
                <label for="email">Почта</label>
                <input id="email" name="email" type="text" class="w-full shadow-sky-200 shadow p-[20px] rounded-[10px]"
                       placeholder="Почта" value="{{ $member->email  }}">
                @error('email')
                <div>
                    {{ $message }}
                </div>
                @enderror
            </div>
            <div>
                <input name="user_id" type="hidden" value="{{ $member->user_id  }}">
                @error('user_id')
                <div>
                    {{ $message }}
                </div>
                @enderror
            </div>


            <div>
                <label for="centers_id">Выберите центр</label>
                <select id="centers_id" name="centers_id">

                    @foreach($centers as $center)

                        <option value="{{ $center->id }}"
                                @if($center->id == $member->centers_id) selected @endif>{{ $center->name }}</option>

                    @endforeach

                </select>
                @error('centers_id')
                <div>
                    {{ $message }}
                </div>
                @enderror

            </div>

            <div>
                <label for="diseases">Сопутствующие заболевания</label>
                <select id="diseases" name="diseases[]" multiple>
                    @foreach($diseases as $disease)
                        <option @selected(in_array( $disease->id,$memberDiseasesIds)) value="{{$disease->id}}"> {{ $disease->name }}</option>
                    @endforeach
                </select>
                @error('diseases')
                <div>
                    {{ $message }}
                </div>
                @enderror

            </div>
            <div>
                <label for="rehabilitation">
                    Посещение других реабилитационных программ
                </label>
                <select id="rehabilitation" name="rehabilitation[]" multiple required>
                    @foreach($rehabilitations as $rehabilitation)
                        <option
                            @selected(in_array( $rehabilitation->id,$memberRehabilitationsIds)) value="{{ $rehabilitation->id }}">{{ $rehabilitation->name }}</option>
                    @endforeach
                </select>
                @error('rehabilitation')
                <div>
                    {{ $message }}
                </div>
                @enderror

            </div>

            <div>
                <label for="physical_condition">Общее физическое состояние</label>
                <select id="physical_condition" name="physical_condition">
                    <option @selected($member->physical_condition === 'прекрасное') value="прекрасное">прекрасное
                    </option>
                    <option @selected($member->physical_condition === 'хорошее') value="хорошее">хорошее</option>
                    <option @selected($member->physical_condition === 'удовлетворительное') value="удовлетворительное">
                        удовлетворительное
                    </option>
                    <option
                        @selected($member->physical_condition === 'неудовлетворительное') value="неудовлетворительное">
                        неудовлетворительное
                    </option>
                    </option>
                </select>
                @error('physical_condition')
                <div>
                    {{ $message }}
                </div>
                @enderror

            </div>



            <div>
                <label for="behavior">
                    Особенности поведения, свойственные ребенку
                </label>
                <select id="behavior" name="behavior[]" multiple>
                    @foreach($behaviors as $behavior)
                        <option @selected(in_array( $behavior->id,$memberBehaviorsIds)) value="{{ $behavior->id }}">{{ $behavior->name }}</option>
                    @endforeach
                </select>
                @error('behavior')
                <div>
                    {{ $message }}
                </div>
                @enderror

            </div>
            <div>
                <label for="skills_id">Какими навыками обладает ребенок</label>
                <select id="skills_id" name="skills[]" multiple required>
                    @foreach($skills as $skill)
                        <option
                            @selected(in_array($skill->id,$memberSkillsIds)) value="{{ $skill->id }}">{{ $skill->name }}</option>
                    @endforeach
                </select>
                @error('skills')
                <div>
                    {{ $message }}
                </div>
                @enderror

            </div>
            <div>
                <label for="walking">
                    Характеристика навыков ходьбы
                </label>
                <select id="walking" name="walking[]" multiple>
                    @foreach($walkings as $walking)
                        <option @selected(in_array($walking->id,$memberWalkingsIds)) value="{{ $walking->id }}">{{ $walking->name }}</option>
                    @endforeach
                </select>
                @error('walking')
                <div>
                    {{ $message }}
                </div>
                @enderror

            </div>

            <input type="submit" value="Обновить" class="bg-blue-700 p-4 text-white font-bold">
        </form>
    </div>
@endsection
